package com.weipt.lambda;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @program: Learning
 * @description: 测试求和，最大值，最小
 * @Company: 汇华(北京)信息咨询服务有限公司
 * @author: peter.wei
 * @create: 2020-07-29 17:07
 **/
public class testReduce {

    private static final List<Integer> numbers = Arrays.asList(1, 5, 3, 8);

    public static void main(String[] args) {
        getMax1();
        getMax2();
        getSum1();
    }




    private static void getMax1(){
        Optional<Integer> reduce = numbers.stream().reduce(Integer::max);
        System.out.println(reduce.get());
    }

    private static void getMax2(){
        Optional<Integer> reduce = numbers.stream().reduce((a, b) -> a > b ? a : b);
        System.out.println(reduce.get());
    }

    private static void getSum1(){
        Optional<Integer> reduce = numbers.stream().reduce(Integer::sum);
        System.out.println(reduce.get());
    }

}